<!-- 网站信息 -->
<template>
    <div class="login-register">
        <el-form ref="formRef" :rules="rules" :model="formData" label-width="120px">
            <el-card shadow="never" class="!border-none">
                <div class="font-medium mb-7">提现设置</div>

                <el-form-item label="提现方式" prop="withdraw_way">
                    <div>
                        <el-checkbox-group v-model="formData.withdraw_way">
                            <el-checkbox label="1">账户余额（默认）</el-checkbox>
                            <el-checkbox label="2">微信零钱</el-checkbox>
                            <el-checkbox label="3">银行卡</el-checkbox>
                            <el-checkbox label="4">微信收款码</el-checkbox>
                            <el-checkbox label="5">支付宝收款码</el-checkbox>
                        </el-checkbox-group>
                        <div class="form-tips">默认需要保留至少一种提现方法</div>
                    </div>
                </el-form-item>

                <el-form-item label="微信零钱接口" prop="coerce_mobile">
                    <div>
                        <el-radio-group v-model="formData.transfer_way" class="ml-4">
                            <el-radio :label="1">企业付款到零钱</el-radio>
                            <el-radio :label="2">商家转账到零钱</el-radio>
                        </el-radio-group>
                        <div class="form-tips">选择商家转账到零钱时，运营账户必须有钱才能提现</div>
                    </div>
                </el-form-item>

                <el-form-item label="最低提现金额" prop="login_agreement">
                    <div>
                        <el-input v-model="formData.withdraw_min_money" placeholder="请输入">
                            <template #append>元</template>
                        </el-input>

                        <div class="form-tips">用户提现需满足最低提现金额。才能提交提现申请。</div>
                    </div>
                </el-form-item>

                <el-form-item label="最高提现金额" prop="请输入">
                    <div>
                        <el-input v-model="formData.withdraw_max_money" placeholder="Please input">
                            <template #append>元</template>
                        </el-input>
                        <div class="form-tips">用户提现允许的最高提现金额。</div>
                    </div>
                </el-form-item>

                <el-form-item label="提现手续费">
                    <div>
                        <el-input v-model="formData.withdraw_service_charge" placeholder="请输入">
                            <template #append>%</template>
                        </el-input>
                        <div class="form-tips">用户提现时收取的手续费占比。</div>
                    </div>
                </el-form-item>
            </el-card>
        </el-form>

        <footer-btns>
            <el-button type="primary" @click="handleSubmit">保存</el-button>
        </footer-btns>
    </div>
</template>

<script lang="ts" setup name="loginRegister">
import { getWithdrawConfig, setWithdrawConfig } from '@/api/setting/user'
import type { FormInstance, FormRules } from 'element-plus'
const formRef = ref<FormInstance>()

// 表单数据
const formData = reactive<any>({
    withdraw_way: [],
    withdraw_min_money: '',
    withdraw_max_money: '',
    withdraw_service_charge: '',
    transfer_way: ''
})

// 表单验证
const rules = reactive<FormRules>({
    withdraw_way: [{ required: true, trigger: 'blur', message: '请选择提现方式' }]
})

// 获取登录注册数据
const getData = async () => {
    try {
        const data = await getWithdrawConfig()
        for (const key in formData) {
            //@ts-ignore
            formData[key] = data[key]
        }
    } catch (error) {
        console.log('获取=>', error)
    }
}

// 保存登录注册数据
const handleSubmit = async () => {
    await formRef.value?.validate()
    try {
        await setWithdrawConfig(formData)
        getData()
    } catch (error) {
        console.log('保存=>', error)
    }
}

getData()
</script>

<style lang="scss" scoped></style>
